/*
 * $Id: string_dup.c,v 1.2 2006-04-06 16:25:37 bacon Exp $
 */

#if defined(__MSTRING)
#include <xp/bas/mstring.h>
#elif defined(__WSTRING)
#include <xp/bas/mstring.h>
#else
#include <xp/bas/string.h>
#endif

#include <xp/bas/memory.h>

xp_char_t* xp_strdup (const xp_char_t* str)
{
	xp_char_t* tmp;

	tmp = (xp_char_t*)xp_malloc ((xp_strlen(str)+1)*xp_sizeof(xp_char_t));
	if (tmp == XP_NULL) return XP_NULL;

	xp_strcpy (tmp, str);
	return tmp;
}

xp_char_t* xp_strxdup (const xp_char_t* str, xp_size_t len)
{
	xp_char_t* tmp;

	tmp = (xp_char_t*)xp_malloc ((len+1)*xp_sizeof(xp_char_t));
	if (tmp == XP_NULL) return XP_NULL;

	xp_strncpy (tmp, str, len);
	return tmp;
}

xp_char_t* xp_strxdup2 (
	const xp_char_t* str1, xp_size_t len1,
	const xp_char_t* str2, xp_size_t len2)
{
	xp_char_t* tmp;

	tmp = (xp_char_t*) xp_malloc (
		(len1 + len2 + 1) * xp_sizeof(xp_char_t));
	if (tmp == XP_NULL) return XP_NULL;

	xp_strncpy (tmp, str1, len1);
	xp_strncpy (tmp + len1, str2, len2);
	return tmp;
}
